package com.zero.lite.admin.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zero.lite.dao.entity.Region;
import com.zero.lite.dao.service.IRegionService;
import com.zero.lite.dao.utils.ResponseUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.zero.lite.admin.annotation.LoginAdmin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/region")
public class RegionController {
    private final Log logger = LogFactory.getLog(RegionController.class);

    @Autowired
    private IRegionService regionService;

    @GetMapping("/clist")
    public Object clist(@LoginAdmin Integer adminId, Integer id) {
        if (id == null) {
            return ResponseUtil.badArgument();
        }
        EntityWrapper ew=new EntityWrapper();
        ew.eq("pid",id);
        List<Region> regionList = regionService.selectList(ew);

        return ResponseUtil.ok(regionList);
    }

    @GetMapping("/list")
    public Object list(@LoginAdmin Integer adminId,
                       String name, Integer code,
                       Page page){
        if(adminId == null){
            return ResponseUtil.unlogin();
        }

        EntityWrapper<Region> ew=new EntityWrapper<>();
        Page<Region> data=regionService.selectPage(page,ew);

        return ResponseUtil.PageOk(data);

    }
}
